import numpy as np
import tensorflow.compat.v1 as tf
import tensorflow.Session as sess
tf.disable_v2_behavior()
# # # print(tf.__version__) 


x = tf.Variable(tf.float32,[None,1])#实际变量

W = tf.Variable(tf.zeros([1,1]))

b = tf.Variable(tf.zeros([1]))

y = tf.matmul(x,W)+b#预测值

y_ = tf.Variable(tf.float32,[None,1])#实际值

cost = tf.reduce_sum(tf.pow((y_-y),2))

for i in range(10):
    xs = np.array([[i]])
    ys = np.array([[2*i]])

train_step = tf.train.GradientDescentOptimizer(0.00001).minimize(cost)#步长/学习率

feed = {x:xs,y_:ys}
sess.run(train_step,feed_dict=feed)

print("After %d iteration:"%i)
print("W:%f"%tf.sess.run(W))
print("b:%f"%tf.sess.run(b))


